﻿using HDS.Data;
using HDS.IService.Log;
using HDS.Model;
using HDS.Model.Entity.Log;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace HDS.Service.Log
{
    public class UpdateLogService : IUpdateLogService
    {
        private LogDbContext logDbContext = new LogDbContext();

        public async Task Add(UpdateLog entity)
        {
            await logDbContext.UpdateLog.InsertAsync(entity);
        }

        public async Task Add(List<UpdateLog> entityList)
        {
            await logDbContext.UpdateLog.InsertRangeAsync(entityList);
        }

        public async Task<DataPagingModel<UpdateLog>> GetList(int pageIndex, int pageSize, Expression<Func<UpdateLog, bool>> whereExpression)
        {
            RefAsync<int> total = 0;
            var rows = await logDbContext.Db.Queryable<UpdateLog>().WhereIF(whereExpression != null, whereExpression).OrderBy(e => e.LogId, OrderByType.Desc).ToPageListAsync(pageIndex, pageSize, total);
            return new DataPagingModel<UpdateLog>
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                PageTotal = (total.Value + pageSize - 1) / pageSize,
                Total = total.Value,
                Rows = rows
            };
        }
    }
}
